/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom.bridge.major;

import java.util.Collection;
import java.util.Collections;
import ru.jSkyRoom.bridge.sub.QuestStageBridge;
import ru.jSkyRoom.interfaces.major.Quest;
import ru.jSkyRoom.interfaces.stub.JSkyScriptPackage;
import ru.jSkyRoom.interfaces.sub.JSkyQuestStage;
import skyproc.Condition;
import skyproc.QUST;
import skyproc.QUST.QuestFlags;
import skyproc.QUST.QuestStage;
import skyproc.ScriptPackage;

/**
 *
 * @author Rakev
 */
public class QuestBridge extends NamedMajorBridge<QUST> implements Quest {

    public QuestBridge(QUST adapting) {
        super(adapting);
    }

    @Override
    public JSkyScriptPackage getScriptPackage() {
        ScriptPackage scriptPackage = getRawObject().getScriptPackage();
        return getBridgeFactory().createBridge(scriptPackage);
    }

    @Override
    public Collection<Condition> getConditions() {
        Collection<Condition> result = getRawObject().getConditions();
        return Collections.unmodifiableCollection(result);
    }

    @Override
    public void addCondition(Condition condition) {
        getRawObject().addCondition(condition);
    }

    @Override
    public void removeCondition(Condition condition) {
        getRawObject().removeCondition(condition);
    }

    @Override
    public int getPriority() {
        return getRawObject().getPriority();
    }

    @Override
    public void setPriority(int priority) {
        getRawObject().setPriority(priority);
    }

    @Override
    public boolean getFlag(QuestFlags flag) {
        return getRawObject().get(flag);
    }

    @Override
    public void setFlag(QuestFlags flag) {
        getRawObject().set(flag, true);
    }

    @Override
    public void unsetFlag(QuestFlags flag) {
        getRawObject().set(flag, false);
    }

    @Override
    public QUST.QuestType getQuestType() {
        return getRawObject().getQuestType();
    }

    @Override
    public void setQuestType(QUST.QuestType type) {
        getRawObject().setQuestType(type);
    }

    @Override
    public String getShortName() {
        return getRawObject().getShortName();
    }

    @Override
    public void setShortName(String shortName) {
        getRawObject().setShortName(shortName);
    }

    @Override
    public String getObjectWindowFilter() {
        return getRawObject().getObjectWindowFilter();
    }

    @Override
    public void setObjectWindowFilter(String name) {
        getRawObject().setObjectWindowFilter(name);
    }

    @Override
    public Collection<JSkyQuestStage> getStages() {
        Collection<QuestStage> rawStages = getRawObject().getStages();
        Collection<? extends QuestStageBridge> stages = getBridgeFactory().createBridges(rawStages, QuestStageBridge.class);
        return Collections.<JSkyQuestStage>unmodifiableCollection(stages);
    }

    @Override
    public void addStage(JSkyQuestStage stage) {
        if (stage instanceof QuestStageBridge) {
            QUST.QuestStage raw = ((QuestStageBridge) stage).getRawObject();
            getRawObject().addStage(raw);
        } else {
            throw new IllegalArgumentException("Supported only QuestStageBridge");
        }
    }

    @Override
    public void removeStage(JSkyQuestStage stage) {
        if (stage instanceof QuestStageBridge) {
            QUST.QuestStage raw = ((QuestStageBridge) stage).getRawObject();
            getRawObject().getStages().remove(raw);
        } else {
            throw new IllegalArgumentException("Supported only QuestStageBridge");
        }
    }

    @Override
    public Collection<QUST.QuestObjective> getObjectives() {
        return getRawObject().getObjectives();
    }

    @Override
    public void addObjective(QUST.QuestObjective objective) {
        getRawObject().addObjective(objective);
    }

    @Override
    public void removeObjective(QUST.QuestObjective objective) {
        getRawObject().getObjectives().remove(objective);
    }

    @Override
    public Collection<QUST.Alias> getAliases() {
        return getRawObject().getAliases();
    }

    @Override
    public void addAlias(QUST.Alias alias) {
        getRawObject().addAlias(alias);
    }

    @Override
    public void removeAlias(QUST.Alias alias) {
        getRawObject().getAliases().remove(alias);
    }
}
